package com.jsoft.jsofted.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.binding.annotation.BindField;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import com.jsoft.jsofted.framework.entity.OfTenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.StringUtils;

/**
 * 人员职位表：用来存储人员所在的岗位有哪些？
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Table("sys_user_post")
@TableName("sys_user_post")
public class UserPostEntity extends OfTenantEntity {

    @Column
    @IsNotNull
    @Unique(value="userOrgPost", columns = {"user_id", "org_id", "post_id"})
    protected Long userId;

    @TableField(exist = false)
    @BindField(entity = UserEntity.class, field = "name", condition = "user_id=id")
    protected String userName;

    @Column
    @IsNotNull
    protected Long orgId;

    @TableField(exist = false)
    @BindField(entity = OrgEntity.class, field = "name", condition = "org_id=id")
    protected String orgName;

    @TableField(exist = false)
    @BindField(entity = OrgEntity.class, field = "fullName", condition = "org_id=id")
    protected String orgFullName;

    @Column
    @IsNotNull
    protected Long postId;

    @TableField(exist = false)
    @BindField(entity = PostEntity.class, field = "name", condition = "post_id=id")
    protected String postName;

    public String getOrgFullName() {
        if (StringUtils.hasText(orgFullName)) {
            return this.orgFullName;
        }
        return this.orgName;
    }
}
